package com.gxgeek.springbootquartz.task;

import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * @author gaoxing
 * @create 2017-12-12 上午10:13
 */
@Configuration
public class QuartConfig {


    @Autowired
    private SpringJobFactory springJobFactory;

    @Bean
    public Scheduler schedulerFactoryBean() throws Exception {
        SchedulerFactoryBean factoryBean=new SchedulerFactoryBean();
        factoryBean.setJobFactory(springJobFactory);
        factoryBean.afterPropertiesSet();
        Scheduler scheduler=factoryBean.getScheduler();
        //延迟60秒启动
        // scheduler.startDelayed(60);

        scheduler.start();
        return scheduler;
    }

//    @Bean
//    public Scheduler scheduler() {
//        return schedulerFactoryBean().getScheduler();
//    }

}